var isDebug = true;
//service-----------------------------------
function vd(obj) {
    var out = "";
    if(obj && typeof(obj) == "object"){
        for (var i in obj) {
            out += i + ": " + obj[i] + "\n";
        }
    } else {
        out = obj;
    }
    alert(out);
}

//calculator---------------------------------
function Point(x, y){
    this.x = null;
    this.y = null;
    
    this.SetX = function(x){
        if (x<0 || x>1) {
            if (isDebug) console.debug("SetX : argument < 0 or argument > 1 !");
            return false;
        }
        this.x = x;
        return true;
    }
    
    this.SetY = function(y){
        if (y<0 || y>1){
            if (isDebug) console.debug("SetY : argument <0 or >1 !");
            return false;
        }
        this.y = y;
        return true;
    }
    
    this.SetXY = function(x, y){
        if (this.SetX(x) && this.SetY(y)) return true;
            return false;
    }
    
    this.IsValid = function(){
        if (this.x != null && this.y != null) return true;
        return false;
    }
    
    this.SetXY(x, y);
}

function Bezier(points){
    this.degree = -1;
    this.points = new Array();
    
    this.SetPoints = function(points){
        if (!(points instanceof Array)){
            if (isDebug) console.debug("SetPoints : argument not instance of Array !");
            return false;
        }
        if (points.length < 1){
            if (isDebug) console.debug("SetPoints : argument length = 0 !");
            return false;
        }
        if (points.length > 4){
            if (isDebug) console.debug("SetPoints : argument length > 4 !" + points);
            return false;
        }
        for (var i=0; i< points.length; i++){
            var currentPoint = points[i]; 
            if (currentPoint == null){
                if (isDebug) console.debug("SetPoints : argument["+i+"] is empty !");
                return false;
            }
            if (!(currentPoint instanceof Point)){
                if (isDebug) console.debug("SetPoints : argument["+i+"] not instance of Point !");
                return false;
            }
            if (!currentPoint.IsValid()){
                if (isDebug) console.debug("SetPoints : argument["+i+"] not is valid !");
                return false;
            }
        }
        this.points = points;
        this.degree = this.points.length - 1;
    }
    
    this.SetPoints(points);    
}

function Figure(){
    this.beziers = new Array();
    
    this.AddBezier = function(bezier){
        if (!(bezier instanceof Bezier)){
            if (isDebug) console.debug("AddBezier : argument not instance of Bezier !");
            return false;
        }
        this.beziers.push(bezier);
    }
}

function Door(width, height){
    this.systemElements = new Array();
    this.fillElements = new Array();
    this.systemLayout = null;
    this.fillLayout = null;
    
    this.CreateSystemLauoyt = function(){
        
    }
}

function Aperture(width, height){
    this.width = null;
    this.height = null;
    
    this.setWidth = function(){
        
    }
}

$(function(){
    if (isDebug) console.debug('\n --- NEW SESSION ---\nStart init calculator !');
    
    /*var p1 = new Point(0.7, 5);
    var p2 = new Point(0.3, 0.4);
    var p3 = new Point(0.4, 0.2);
    var p4 = new Point(0.5, 0.1);
    
    var line = new Bezier(new Array(p1, p2, p3, p4));
    */
    
    var ap = new Aperture()
    
    if (isDebug) console.debug('Finish init calculator !');
});